package com.walter.springcloud.computer.services;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * ComputerController
 *
 * @author zhuyuwei
 * @date 2017/4/28
 */
@RestController
public class ComputerController {
    private final static Logger logger = LoggerFactory.getLogger(ComputerController.class);

    @Autowired
    private DiscoveryClient client;

    @GetMapping(value = "/add")
    public String add(@RequestParam("a") Integer a, @RequestParam("b") Integer b) {
        ServiceInstance instance = client.getLocalServiceInstance();
        Integer result = a + b;
        logger.info("/add, host: {}, service_id：{}, result: {}", instance.getHost(), instance.getServiceId(), result);
        return "Hello World, result: " + result;
    }
}
